<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/4/17
 * Time: 17:15
 */

namespace App\Rep;


use App\Models\DispatchOrder;
use Illuminate\Support\Facades\DB;

class DispatchOrderRep
{

    /**
     * 获取排单顺序列表
     * @param $params
     */
    public function getDispatchOrderListRep($params){
        return DispatchOrder::Search($params)->orderBy('sort','asc')->get();
    }

    /**
     * 设置派单顺序
     * @param $params
     */
    public function setDispatchOrderRep($params){
        DB::beginTransaction();
        try{
            $arr = $params['sort_arr'];
            foreach($arr as $k=>$v){
                DispatchOrder::where('id',$v['id'])->update(['sort'=>$v['sort']]);
            }
            DB::commit();
            return ['code'=>0,'msg'=>'success','data'=>[]];
        }catch(\Exception $exception){

            DB::rollBack();
            return ['code'=>2001,'msg'=>$exception->getMessage(),'data'=>[]];
        }

    }

    /**
     * 获取派单顺序
     */
    public function getDispatchOrderSortRep(){
        $list = DispatchOrder::where('is_del',2)->orderBy('sort','asc')->get()->toArray();
        return $list;
    }

}